/**
 * 生成 Marker 内容
 * @param {string} name 标题
 * @param {string} note 注释
 * @param {string} img 图片链接
 * @param {string} type 类别：颜色
 * @param {number} index 序号
 * @returns {string} 生成的HTML内容
 */
const api_url = import.meta.env.VITE_APP_BASE_API;
function generateMarkerContent(name, note, img, type, index) {
    const indexClass = isNaN(Number(index)) ? 'hidden' : '';
    const typeClass = type ? ` ${type}` : '';
    
    if (img && note) {
        return `
            <div class="marker${typeClass}">
                <div class="marker-index">
                    <div class="index ${indexClass}">${index + 1}</div>
                    <div class="title">${name}</div>
                </div>
                <div class="marker-content">
                    <div class="note">${note.replace(/\n/g, '<br>')}</div>
                    <div class="view">
                        <a target="_blank" href="${api_url + img}">
                            <img src="${api_url + img}" alt="view">
                        </a>
                    </div>
                </div>
            </div>`;
    } else if (img) {
        return `
            <div class="marker${typeClass}" >
                <div class="marker-index">
                    <div class="index ${indexClass}">${index + 1}</div>
                    <div class="title">${name}</div>
                </div>
                <div class="marker-content">
                    <div class="view">
                        <a target="_blank" href="${api_url + img}">
                            <img src="${api_url + img}" alt="view">
                        </a>
                    </div>
                </div>
            </div>`;
    } else if (note) {
        return `
            <div class="marker${typeClass}">
                <div class="marker-index">
                    <div class="index ${indexClass}">${index + 1}</div>
                    <div class="title">${name}</div>
                </div>
                <div class="marker-content">
                    <div class="note">${note.replace(/\n/g, '<br>')}</div>
                </div>
            </div>`;
    } else {
        return `
            <div class="marker no-content${typeClass}">
                <div class="marker-index">
                    <div class="index ${indexClass}">${index + 1}</div>
                    <div class="title">${name}</div>
                </div>
            </div>`;
    }
}

// 导出函数供其他模块使用
export { generateMarkerContent };
